$.fn.toJSO = function() {
	var obj = {}, $kids = $(this).find('[name]');
	if (!$kids.length) {
		return $(this).val();
	}
	$kids.each(function() {
		var $el = $(this), name = $el.attr('name');
		if ($el.siblings("[name=" + name + "]").length) {
			if (!/radio|checkbox/i.test($el.attr('type'))
					|| $el.prop('checked')) {
				obj[name] = obj[name] || [];
				obj[name].push($el.toJSO());
			}
		} else {
			obj[name] = $el.toJSO();
		}
	});
	return obj;
};

(function($) {
	$.fn.serializeJson = function() {
		var serializeObj = {};
		var array = this.serializeArray();
		var str = this.serialize();
		$(array).each(
				function() {
					if (serializeObj[this.name]) {
						if ($.isArray(serializeObj[this.name])) {
							serializeObj[this.name].push(this.value);
						} else {
							serializeObj[this.name] = [
									serializeObj[this.name], this.value ];
						}
					} else {
						serializeObj[this.name] = this.value;
					}
				});
		return serializeObj;
	};
})(jQuery);

JSON.stringify = JSON.stringify || function (obj) {
    var t = typeof (obj);
    if (t != "object" || obj === null) {
        // simple data type
        if (t == "string") obj = '"'+obj+'"';
        return String(obj);
    }
    else {
        // recurse array or object
        var n, v, json = [], arr = (obj && obj.constructor == Array);
        for (n in obj) {
            v = obj[n]; t = typeof(v);
            if (t == "string") v = '"'+v+'"';
            else if (t == "object" && v !== null) v = JSON.stringify(v);
            json.push((arr ? "" : '"' + n + '":') + String(v));
        }
        return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
    }
};